#pragma once
#include "Global References/BaseObject.h"	
#include "Global References/VectorContainer.h"
#include "User Interface/Gui_References.h"
#include "../../Global References/timer.h"
#include "Item/Items.h"
#define oneLength 5	//For adding textboxes

enum Morphs
{
	MORPH_NULL,
	MORPH_BUTTON,
	MORPH_PANEL,
	MORPH_TUTORIAL,
	MORPH_INPUT,
	MORPH_INVENTORY,
	MORPH_ICON,
	MORPH_SIZE
};
enum buttonType
{
	BUTTON_ERROR_CONFIRM,
	BUTTON_SINGLEPLAYER,
	BUTTON_MULTIPLAYER,
	BUTTON_PRELOAD,
	BUTTON_GAME_PLAY,	//Go back to playing the game
	BUTTON_CLIENT,
	BUTTON_SERVER,
	BUTTON_CLOSE_DEBUG_MENU,
	BUTTON_TOGGLE_AUTOLOOT,
	NOBUTTON = -1
};

class gui_base : public BaseObject
{
protected:
	Morphs morphType;		//What manner of object this is
	int m_ishowState;

public:
	void init (Vector2D Asset,Morphs Morph, int ShowState);
	//=====ACCESSORS
	Morphs	getMorph(){return morphType;}
};
class gui_panel : public gui_base
{
protected:
	short		m_iElements;	//Number of elements to write
	short		m_iAllocated;	//How many spaces we've allocated
	Vector2D	dimensions;		//Width and Height
	TextBox*	m_tbTexts;		//All the values to be written
public:
	gui_panel(){};
	void init(Vector2D AssetID, Vector2D Pos,int showState);
	void init(Vector2D AssetID, Quad Dims,int showState);
	void reset(Quad Dims,int showState);
	void update(short currentState);

	void addTextBox(Quad Pos, char* Value);
	void modifyTBox(Quad Pos, char* Value,int index);
	void modifyText(char* a_message);
	//=====Accessors
	bool checkCollision(POINT Mouse);		// Does nothing but check to see if the mouse is within its bounds
	TextBox	accessText(short Index);		//Returns the textbox at index
	short numElements(){return m_iElements;};	//Returns # of Textboxes
	Quad getDimensions(){return Quad(short(getPos().x),short(getPos().y),short(dimensions.x),short(dimensions.y));};
	~gui_panel(){delete m_tbTexts;m_tbTexts = NULL;};

};
class gui_tutorial : public gui_panel
{
protected:
	int duration;	//How long after popping in before the window pops out (in seconds)
	int timeBegan;

	bool popInComplete;
	bool durationComplete;
	bool popOutComplete;


	void popIn()
	{
		if(!popInComplete)
		{
			float x,y,z;

			x = getScale().x;
			y = getScale().y;
			z = getScale().z;

			x += 0.1f;
			y += 0.1f;
			z += 0.1f;

			if(y > 1)
				setScale(1,1,1);
			else
				setScale(x,y,z);

			if(getScale().y >= 1)						
				popInComplete = true;
		}
	};
	void popOut()
	{
		bool timeDone(clock() - timeBegan > (duration * 1000));
		if(!popOutComplete && timeDone)
		{
			float x,y,z;

			x = getScale().x;
			y = getScale().y;
			z = getScale().z;

			x -= 0.1f;
			y -= 0.1f;
			z -= 0.1f;

			if(y < 0)	setScale(0,0,0);
			else		setScale(x,y,z);

			if(getScale().y <= 0)						
				popOutComplete = true;
		}
	};

public:
	gui_tutorial(){};

	void reset()
	{
		active				= false;
		popInComplete		= false;
		durationComplete	= false;
		popOutComplete		= false;
		timeBegan			= 0;
	}
	void stop()
	{
		active				= false;
		popInComplete		= true;
		durationComplete	= true;
		popOutComplete		= true;
		timeBegan			= 0;
	}

	void init(Vector2D AssetID, Vector2D Pos,int showState, int appearLengthInSeconds)
	{
		gui_panel::init(AssetID,Pos,showState);
		this->setScale(0,0,0);
		morphType = MORPH_TUTORIAL;
		duration = appearLengthInSeconds;
		timeBegan = 0;
		popInComplete		= false;
		durationComplete	= false;
		popOutComplete		= false;

	}
	bool update(short currentState)
	{
		if(currentState == STATE_GAME && !durationComplete)
		{
			active = true;
			if(!timeBegan)	
			{
				timeBegan = clock();	//Set the timer, then skip the rest
			}
			else			(popInComplete?popOut():popIn());
		}
		else
			active = false;
		return popOutComplete;
	};
};


class gui_button : public gui_panel
{
protected:
	buttonType	m_eID;		//enum holding what the ID is for the button
	short		m_sPressed;	//-1: Delete Selection, 0: Not Pressed, 1: Pressed
public:
	enum state{
		DELETETHIS = -1,
		NOTPRESSED,
		PRESSED
	};

	gui_button(){};
	void init(Vector2D assetID, short showState, Quad Dim, buttonType buttonID);
	bool checkClicked	(POINT Mouse);
	bool isPressed()	{return (m_sPressed == NOTPRESSED? 0:1);};	//Returns a yes or no on whether pressed
	short valuePressed(){return m_sPressed;};				//Returns the exact value of the press
	void resetPressed()	{m_sPressed = NOTPRESSED;}
	void shiftPressed() {m_sPressed = DELETETHIS;};
	int	buttonID()		{return m_eID;};
	~gui_button()		{delete m_tbTexts; m_tbTexts = NULL;}


};
class gui_icon : public gui_button
{
private:
	int		m_eID;
public:
	gui_icon(){};
	char*	hoverText; //Text shown when the mouse hovers over the object.

	~gui_icon(){delete m_tbTexts; m_tbTexts = NULL;}
	void init(Vector2D assetID, short a_showState, Quad Dim, int buttonID);
	int	buttonID()		{return m_eID;};

};
class gui_input :public gui_panel
{
protected:
	char** wordMorph;
public:
	gui_input(){};
	void  init(Vector2D AssetID,Quad Rect,int showState, char** textToMod);
	void  update(short currentState);
	void  addTextBox(){/*Not allowed to add text boxes. Because: No*/};
	~gui_input(){delete m_tbTexts;delete [] wordMorph;m_tbTexts = NULL; wordMorph = NULL;}

};